const { getCommentList, addComment } = require('../controller/comment')
const { SuccessModel, ErrorModel } = require('../model/resModel')

const handleCommentRouter = (req, res) => {
  // 评论列表
  if (req.method === 'GET' && req.path === '/api/comment/list') {
    return getCommentList(req.query).then(data => {
      if (data) {
        return new SuccessModel(data)
      } else {
        return new ErrorModel(data)
      }
    })
  }

  // 添加评论
  if (req.method === 'POST' && req.path === '/api/comment/add') {
    return addComment(req.body).then(data => {
      if (data) {
        return new SuccessModel({}, '评论成功')
      } else {
        return new ErrorModel({}, '评论失败')
      }
    })
  }
}

module.exports = handleCommentRouter
